package com.mujiwulian.vue.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mujiwulian.vue.UserResult;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
public class RestControllerTest {
    @Autowired
    private UserResult user;

    @GetMapping("/getAll")
    public JSONArray getAll(){
        List strings= new ArrayList(){};
        strings.add("张三");
        strings.add("李四");
        strings.add("王二麻子");
        //转换成json字符串
        String names=JSONObject.toJSONString(strings);
        JSONArray jsonArray=JSON.parseArray(names);
        return jsonArray;
    }
//
    @DeleteMapping("/{id}/deletion")
    public UserResult delete(@PathVariable("id") @ApiParam("传入一个博客的id") Integer id){
        user.setCode(1);
        user.setMsg("查询成功");
        user.setId(id);
        System.out.println();
        return user;
    }
}
